package com.takeaway.dao.daolmpl;

import com.takeaway.dao.daointerface.ShopDao;
import com.takeaway.pojo.Shop;
import com.takeaway.utils.JdbcUtils;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 后台赖骏
 */
public class ShopDaoImpl implements ShopDao {
    @Override
    public int insert(Shop shop) throws Exception{
        return JdbcUtils.insert(shop);
    }

    @Override
    public int delete(Class<Shop> clz, String[] checkField, Object... factor) throws Exception{
        return JdbcUtils.delete(clz,checkField,factor);
    }

    @Override
    public int update(Shop shop) throws Exception{
        return JdbcUtils.update(shop);
    }

    @Override
    public Shop selectSingle(Shop shop, String[] checkFields, Object... factor) throws Exception{
        return (Shop) JdbcUtils.selectSingle(shop,checkFields,factor);
    }

    @Override
    public ArrayList<Shop> selectMore(Class<Shop> clz,int begin,int listNum) throws Exception{
        return (ArrayList<Shop>) JdbcUtils.selectMore(clz,begin,listNum);
    }

    @Override
    public ArrayList<Shop> selectMore(Class<Shop> clz, String[] checkField, Object... factor) throws Exception{
        return (ArrayList<Shop>) JdbcUtils.selectMore(clz,checkField,factor);
    }

    @Override
    public long selectListNum() throws Exception {
        String sql = "select count(*) from Shop";
        return (long)JdbcUtils.executeSelect(sql);
    }

    @Override
    public List<Shop> selectLikeMore(Class<Shop> clz, String checkFactor) throws Exception {
        String checkLikeFactor = "%"+checkFactor+"%";
        String sql = "SELECT DISTINCT shop.id,shopName,ownerId,shop.description,shopCode,star " +
                "FROM food,shop " +
                "WHERE shop.id=shopId AND shopCode=1 AND " +
                "(dishName LIKE ? OR shopName LIKE ? );";
        return JdbcUtils.executeSelectList(Shop.class,sql,checkLikeFactor,checkLikeFactor);
    }

    @Override
    public List<Shop> selectShop(int begin, int listNum) throws Exception {
        String sql = "select * from shop " +
                "where shopCode=1 limit ? ,?;";
        return JdbcUtils.executeSelectList(Shop.class, sql,begin,listNum);
    }

    @Override
    public List<Shop> selectCollect(int userId) throws Exception {
        String sql = "select shop.* from shop,collect " +
                "where shopId=shop.id and userId = ? ;";
        return JdbcUtils.executeSelectList(Shop.class,sql,userId);
    }


}
